<template>
  <div class="container">
<!--    <div class="opt-area-02">-->
<!--      <div class="right-con">-->
<!--        <div class="input-frame" style="width: 164px">-->
<!--          <Input type="text" @on-click="selectlist(1)" placeholder="请输入姓名" style="width: 164px" v-model="params.name" icon="ios-search"/>-->
<!--        </div>-->
<!--        <div class="input-frame" style="width: 164px">-->
<!--          <Input type="text" @on-click="selectlist(1)" placeholder="请输入电话号码" style="width: 164px" v-model="params.mobile" icon="ios-search"/>-->
<!--        </div>-->
<!--        <div class="input-frame" style="width: 164px">-->
<!--          <Input type="text" @on-click="selectlist(1)" placeholder="订单编号" style="width: 164px" v-model="params.code" icon="ios-search"/>-->
<!--        </div>-->
<!--        <div class="input-frame" style="width: 164px">-->
<!--          <Input type="text" @on-click="selectlist(1)" placeholder="事项id" style="width: 164px" v-model="params.item_id" icon="ios-search"/>-->
<!--        </div>-->
<!--        <Button type="info" size="small" @click="selectlist(1)" style="margin-top: 5px;margin-right:5px">搜索</Button>-->
<!--        <Button type="info" size="small" @click="selectlist" style="margin-top: 5px;margin-right:5px">刷新</Button>-->
<!--      </div>-->
<!--    </div>-->
    <Table :loading="countData.loading" border :columns="columns1" :data="dataList" size="small" ref="table">
      <template slot="action" slot-scope="{ row }">
        <Row style="margin-bottom: 5px; margin-top: 2px">
          <Button class="table-action-btn" type="info" size="small" @click="openChatInfo(row)">聊天</Button>
        </Row>
      </template>
    </Table>
    <template>
      <Row v-if="loadData == true">
        <Col class="demo-spin-col" span="8" offset="8">
          <Spin fix>
            <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
            <div>查询中...</div>
          </Spin>
        </Col>
      </Row>
    </template>
    <Modal v-model="modal" tiele="" :width="600" footer="false">
      <template>
        <div class="talk_show" id="words">
          <div :class="[( i.send_id!='LM40005') ? 'atalk' : 'btalk']" v-for=" (i, v) in list " v-bind:key="v"><span>{{ i.send_name }} ：{{ i.message }}</span></div>
        </div>
        <div class="talk_input">
          <input type="text" class="talk_word" id="talkwords" v-model="text">
          <input type="button" value="发送" class="talk_sub" id="talksub" @click="fnAdd">
        </div>
      </template>
    </Modal>
  </div>
</template>

<script>

import { getMessageUserList, getSystemMessageList, addSystemMessage } from '@/api/mainv3'

export default {
  name: 'index',
  data () {
    return {
      list: [],
      text: '',
      modal: false,
      user_id: '',
      user_name: '',
      disabledShow: false,
      params: { name: '', mobile: '', item_id: '', code: '', pageNo: 1, pageSize: 10, totalRecord: 0 },
      formData: {},
      countData: { loading: false, fcnum: 0, ytbnum: 0, zcnum: 0 },
      columns1: [
        { title: '咨询人', key: 'send_name', align: 'center' },
        { title: '证件号码', key: 'send_id', align: 'center' },
        { title: '创建时间', key: 'create_time', align: 'center' },
        { title: '操作', align: 'center', slot: 'action' }
      ],
      loadData: false,
      dataList: []
    }
  },
  methods: {
    fnAdd () {
      if (this.text == '') {
        alert('请输入内容!')
        return
      }
      addSystemMessage({ receive_id: this.user_id, receive_name: this.user_name, message: this.text }).then(ret => {
        if (ret.data.errcode === 0) {
          this.list.push({ send_id: 'LM40005', send_name: '客服', message: this.text })
          // 每次输入内容后,清空输入栏数据
          this.text = ''
        }
      })
    },
    selectlist (inpageNo) {
      this.loadData = true
      if (inpageNo) {
        this.params.pageNo = inpageNo
      } else {
        this.params.pageNo = 1
      }
      getMessageUserList(this.params).then(ret => {
        if (ret.data.errcode === 0) {
          this.dataList = ret.data.data
          this.loadData = false
          this.params = {
            name: this.params.name,
            mobile: this.params.mobile,
            code: this.params.code,
            item_id: this.params.item_id
          }
        } else {
          this.loadData = true
          this.$Notice.error({
            title: '查询列表信息失败',
            desc: ret.data.errmsg
          })
        }
      })
    },
    openChatInfo (row) {
      this.user_id = row.send_id
      this.user_name = row.send_name
      getSystemMessageList({ send_id: row.send_id }).then(ret => {
        if (ret.data.errcode === 0) {
          this.list = ret.data.data
        }
      })
      this.modal = true
    }
  },
  mounted () {
    this.selectlist()
  }
}
</script>

<style scoped>
.page_style {
  margin: 20px 5px;
}
.input-frame {
  width: 120px;
  margin-right: 10px;
}
.house-list > .group {
  background: white;
  padding: 10px;
  margin-top: 10px;
}
.house-list > .group > .item {
  border-bottom: 1px solid #f5f5f5;
  padding: 10px 0;
}
.house-list > .group > .item .top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
}
.house-list > .group > .item .title {
  font-size: 14px;
  color: #333333;
}
.house-list > .group > .item .address {
  font-size: 12px;
  color: gray;
  display: flex;
  align-items: center;
}
.house-list > .group > .item .detail {
  font-size: 12px;
  color: dodgerblue;
}
.opt-area-02 {
  display: flex;
  align-items: center;
  flex-direction: column;
  border: 1px solid #abdcff;
  background-color: #f0faff;
  padding: 8px 16px 8px 16px;
  border-radius: 4px;
  margin-bottom: 10px;
}
.opt-area-02 .right-con {
  width: 100%;
  margin-top: 5px;
  display: flex;
}
.opt-area-02 .left-con {
  font-size: 14px;
  width: 100%;
}
.opt-area-02 .left-con span {
  font-weight: bold;
}
.opt-area-02 .right-con input {
  width: 150px;
  margin-right: 10px;
}

.opt-area-02 .right-con .input-frame {
  width: 200px;
  margin-right: 10px;
}
.table-action-btn {
  margin-right: 3px;
}
.container >>> .ivu-btn-small {
  height: 24px;
  padding: 0 5px;
  font-size: 12px;
  border-radius: 3px;
}
.btn-action {
  margin-bottom: 10px;
}
.mp10 {
  margin-right: 10px;
}
.title-style {
  color: red;
}
.mb20 {
  margin-bottom: 20px;
}
.mt20 {
  margin-top: 20px;
}
.ivu-table-row {
  height: 57px;
}
.ivu-form-item{
  /*margin-bottom: 0%;*/
}
.talk_show {
  width: 580px;
  height: 420px;
  /*border: 1px solid #666;*/
  background: #fff;
  margin: 0px;
  overflow: auto;
}
.talk_input {
  width: 580px;
  height: 20px;
  margin-top: 10px;
  margin-bottom: 10px;
}
.whotalk {
  width: 80px;
  height: 30px;
  float: left;
  outline: none;
}
.talk_word {
  width: 480px;
  height: 26px;
  padding: 0px;
  float: left;
  margin-right: 10px;
  outline: none;
  text-indent: 10px;
}
.talk_sub {
  width: 56px;
  height: 30px;
  float: left;
  margin-left: 10px;
}
.atalk {
  margin: 10px;
}
.atalk span {
  display: inline-block;
  background: #0181cc;
  border-radius: 10px;
  color: #fff;
  padding: 5px 10px;
}
.btalk {
  margin: 10px;
  text-align: right;
}
.btalk span {
  display: inline-block;
  background: #ef8201;
  border-radius: 10px;
  color: #fff;
  padding: 5px 10px;
}
</style>
